package ar.com.temporis.fixture;

import java.util.Iterator;
import java.util.List;

import ar.com.temporis.framework.domain.Entity;
import ar.com.temporis.framework.repository.Persistor;
import ar.com.temporis.util.collection.CollectionFactory;

/**
 * 
 * @author matias.sulik
 * 
 */
public abstract class SimpleFixture implements Fixture {

	private List<Entity> entities = CollectionFactory.createList();

	private Persistor persistor;

	public SimpleFixture() {
		super();
	}

	public void setPersistor(Persistor persistor) {
		this.persistor = persistor;
	}

	@SuppressWarnings("unchecked")
	protected void add(Entity entity) {
		this.entities.add(entity);
	}

	public final void install() {
		addEntities();
		
		for (Entity entity : this.entities) {			
			this.persistor.save(entity);
		}
	}

	protected abstract void addEntities();
}
